home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / layerEditorWin.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  11.7 KB  |  447 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  11 July 1997
  22. // Author:         jb
  23. //
  24. //
  25. //  Procedure Name:
  26. //        layerEditorWin
  27. //
  28. //  Description:
  29. //        Brings up a window that allows users to manage
  30. //        the layers in the system
  31. //
  32. //  Input Arguments:
  33. //      None.
  34. //
  35. //  Return Value:
  36. //      None.
  37. //
  38.  
  39. proc int isValidName( string $name )
  40. //  Description:
  41. //        This procedure checks if the given string is a valid object
  42. //      name.  It returns true if it is, false otherwise.
  43. //
  44. {
  45.     int $isValid = true;
  46.     // check if name contains invalid characters
  47.     string $regex = "[^0-9a-zA-Z_]";
  48.     string $match = match( $regex, $name );
  49.     if ($match != "") {
  50.         $isValid = false;
  51.         confirmDialog -title "Alert" 
  52.             -button "OK"
  53.             -defaultButton "OK"
  54.             -message "      Name contains illegal characters. Please select another.      "
  55.             -parent layerEditorWnd;
  56.     } else {
  57.         // check if name begins with an alphabetic character
  58.         $regex = "[a-zA-Z_][0-9a-zA-Z_]*";
  59.         $match = match( $regex, $name );
  60.         if ($match != $name) {
  61.                $isValid = false;
  62.             confirmDialog -title "Alert" 
  63.                 -button "OK"
  64.                 -defaultButton "OK"
  65.                   -message "      Name is not valid. Please select another.      "
  66.                 -parent layerEditorWnd;
  67.         }
  68.     }
  69.     return $isValid;
  70. }
  71.  
  72. global proc renameLayer( string $currentLayerName ) {
  73.  
  74.     // If it's not the default universe layer then place dialogue
  75.     if ($currentLayerName != "Universe")
  76.     {
  77.         //
  78.         // Prompt the user for a new layer name
  79.         //
  80.         string $result = `promptDialog 
  81.             -title "Rename Layer"
  82.             -message "Enter New Layer Name:" 
  83.             -text $currentLayerName
  84.             -button "OK" 
  85.             -button "Cancel" 
  86.             -defaultButton "OK" 
  87.             -cancelButton "Cancel" 
  88.             -dismissString "Cancel"
  89.             -parent layerEditorWnd`;
  90.  
  91.         //
  92.         // If the result was "OK", then proceed
  93.         //
  94.         if ( $result == "OK" ) {
  95.  
  96.             //
  97.             // Query the promptDialog for the name the
  98.             // user typed in - note: there is no checking
  99.             // being done for illegal characters, spaces,
  100.             // etc.  This should be added.
  101.             //
  102.             // The set is created in the layer partition 
  103.             // first, then the elements are forced into 
  104.             // the set, so that exclusivity can be maintained,
  105.             // and the set creation won't fail before it's
  106.             // even created.
  107.             //
  108.             string $newLayerName = `promptDialog -q`;
  109.  
  110.             if ( isValidName($newLayerName) ) {
  111.                 if (catch($newLayerName = `rename $currentLayerName $newLayerName`)) {
  112.                     //
  113.                     // error due to non - unique name for context
  114.                     //
  115.                     confirmDialog -title "Alert" 
  116.                         -button "OK"
  117.                         -defaultButton "OK"
  118.                         -message "       Error in trying to rename Layer.  Please select another        "
  119.                         -parent layerEditorWnd;
  120.                 }
  121.                 else {
  122.                     string $layerEntryName = ( $newLayerName + "LayerItem" );
  123.                     string $oldLayerEntryName = ( $currentLayerName + "LayerItem" );
  124.         
  125.                     // change the label of the menu item and rename
  126.                     // the menu item
  127.                     menuItem -e -l $newLayerName $oldLayerEntryName;
  128.                     renameUI $oldLayerEntryName $layerEntryName;
  129.                 }
  130.             }
  131.         }
  132.     } else {
  133.         warning( "Universe layer cannot be renamed" );
  134.     }
  135. }
  136.  
  137.  
  138. global proc updateLayerEditorButtons( )
  139. {
  140.     //    If something is selected in the layer
  141.     //    list, then enable the appropriate buttons,
  142.     //    otherwise disable the ones that require that
  143.     //    sets/layers are selected
  144.     //
  145.     if( 0 == `textScrollList -q -nsi layerList` ) {
  146.         button -e -enable false renameButton;
  147.         button -e -enable false deleteButton;
  148.         button -e -enable false hideButton;
  149.         button -e -enable false showButton;
  150.         button -e -enable false transferButton;
  151.     } else if( 1 == `textScrollList -q -nsi layerList` ) {
  152.         button -e -enable true renameButton;
  153.         button -e -enable true deleteButton;
  154.         button -e -enable true hideButton;
  155.         button -e -enable true showButton;
  156.         button -e -enable true transferButton;
  157.     } else {
  158.         button -e -enable false renameButton;
  159.         button -e -enable true deleteButton;
  160.         button -e -enable true hideButton;
  161.         button -e -enable true showButton;
  162.         button -e -enable false transferButton;
  163.     }
  164. }
  165.  
  166.  
  167. global proc updateLayerEditorWnd( )
  168. {
  169.     //    Fill the set list
  170.     //
  171.     textScrollList -e -ra layerList;
  172.  
  173.     string $layers[] = `listAllLayers`;
  174.  
  175.     for( $item in $layers ) {
  176.         textScrollList -e -a $item layerList;
  177.     }
  178. }
  179.     
  180.  
  181. global proc layerCmd( string $cmd ) 
  182. {
  183.  
  184.  
  185.     switch( $cmd ) {
  186.         case "new":
  187.             createNewLayer;
  188.             updateLayerEditorWnd;
  189.             break;
  190.         case "rename":
  191.             //    Rename the selected sets
  192.             string $selSets[] = `textScrollList -q -si layerList`;
  193.             renameLayer $selSets[0];
  194.             updateLayerEditorWnd;
  195.             break;
  196.         case "transfer":
  197.             //    Transfer selected to selected layer
  198.             string $selSets[] = `textScrollList -q -si layerList`;
  199.             if( size( `ls -sl` ) == 0 ) {
  200.                 warning( "No objects selected to transfer to " + $selSets[0] );
  201.                 return;
  202.             }
  203.             sets -e -fe $selSets[0];
  204.             break;
  205.         case "delete":
  206.             //    Delete the selected sets
  207.             //
  208.             string $selSets[] = `textScrollList -q -si layerList`;
  209.             for( $set in $selSets ) {
  210.                 delete $set;
  211.             }
  212.             updateLayerEditorWnd;
  213.             break;
  214.         case "hide":
  215.             //    Hide the selected sets
  216.             //
  217.             string $selSets[] = `textScrollList -q -si layerList`;
  218.             for( $set in $selSets ) {
  219.                 hide $set;
  220.             }
  221.             break;
  222.         case "show":
  223.             //    Show the selected sets
  224.             //
  225.             string $selSets[] = `textScrollList -q -si layerList`;
  226.             for( $set in $selSets ) {
  227.                 showHidden $set;
  228.             }
  229.             break;
  230.         case "hideall":
  231.             //    Hide all layer sets
  232.             //
  233.             string $layers[] = `listAllLayers`;
  234.             for( $item in $layers ) {
  235.                 hide $item;
  236.             }
  237.             break;
  238.         case "showall":
  239.             //    Hide all layer sets
  240.             //
  241.             string $layers[] = `listAllLayers`;
  242.             for( $item in $layers ) {
  243.                 showHidden $item;
  244.             }
  245.             break;
  246.         case "select":
  247.             //    Select layer sets
  248.             //
  249.             string $selSets[] = `textScrollList -q -si layerList`;
  250.             select -d;
  251.  
  252.             for( $set in $selSets ) {
  253.                 select -add $set;
  254.             }
  255.             break;
  256.         case "template":
  257.             //    Template layer sets
  258.             //
  259.             string $selSets[] = `textScrollList -q -si layerList`;
  260.             select -d;
  261.  
  262.             for( $set in $selSets ) {
  263.                 toggle -template -state on $set;
  264.             }
  265.             break;
  266.         case "untemplate":
  267.             //    Template layer sets
  268.             //
  269.             string $selSets[] = `textScrollList -q -si layerList`;
  270.             select -d;
  271.  
  272.             for( $set in $selSets ) {
  273.                 toggle -template -state off $set;
  274.             }
  275.             break;
  276.         case "selectall":
  277.             //    Select all layer sets
  278.             //
  279.             string $layers[] = `listAllLayers`;
  280.             select -d;
  281.  
  282.             for( $item in $layers ) {
  283.                 select -add $item;
  284.             }
  285.             break;
  286.     }
  287. }
  288.  
  289.  
  290. global proc layerEditorWin( )
  291. {
  292.  
  293.     if( `window -exists layerEditorWnd` ) {
  294.         updateLayerEditorWnd;
  295.         showWindow layerEditorWnd;
  296.         return;
  297.     }
  298.  
  299.    // GG: don't hardcode the HEIGHT! It doesn't work X-platform
  300.     window -t "Layer Editor" -w 223
  301.         -iconName "Layers" 
  302.         -s true layerEditorWnd;
  303.  
  304.         tabLayout layerEditorTabLayout;
  305.         
  306.             formLayout layerEditorForm;
  307.                 textScrollList 
  308.                     -ams true 
  309.                     -dkc "layerCmd delete"
  310.                     -dcc "layerCmd select"
  311.                     -sc "updateLayerEditorButtons"
  312.                     layerList;    
  313.         
  314.  
  315.             separator -style "in" layerSep;
  316.  
  317.                 columnLayout layerEdBtnLayout;
  318.  
  319.                     button -h 26 -w 80 -l "New"         
  320.                         -c "layerCmd new" newButton;
  321.                     button -h 26 -w 80 -l "Rename"         
  322.                         -c "layerCmd rename" -enable false renameButton;
  323.                     button -h 26 -w 80 -l "Remove"         
  324.                         -c "layerCmd delete" -enable false deleteButton;
  325.                     button -h 26 -w 80 -l "Transfer"         
  326.                         -c "layerCmd transfer" -enable false transferButton;
  327.  
  328.                     separator -style "in" -w 80 -h 10;
  329.     
  330.                     button -h 26 -w 80 -l "Hide"         
  331.                         -c "layerCmd hide" -enable false hideButton;
  332.                     button -h 26 -w 80 -l "Hide All"     
  333.                         -c "layerCmd hideall" -enable true hideAllButton;
  334.  
  335.                     separator -style "in" -w 80 -h 10;
  336.  
  337.                     button -h 26 -w 80 -l "Show"         
  338.                         -c "layerCmd show" -enable false showButton;
  339.                     button -h 26 -w 80 -l "Show All"     
  340.                         -c "layerCmd showall" -enable true showAllButton;
  341.  
  342.                     separator -style "in" -w 80 -h 10;
  343.  
  344.                     button -h 26 -w 80 -l "Template"
  345.                         -c "layerCmd template" -enable true templateButton;
  346.                     button -h 26 -w 80 -l "Untemplate"
  347.                         -c "layerCmd untemplate" -enable true unTemplateButton;
  348.     
  349.                     separator -style "in" -w 80 -h 10;
  350.         
  351.                     button -h 26 -w 80 -l "Select"        
  352.                         -c "layerCmd select" -enable true selButton;
  353.                     button -h 26 -w 80 -l "Select All"    
  354.                         -c "layerCmd selectall" -enable true selAllButton;
  355.     
  356.                 setParent ..;
  357.  
  358.                 button -h 26 -w 80 -l "Update"         
  359.                     -c "updateLayerEditorWnd" updateButton;
  360.                 button -h 26 -w 80 -l "Close"         
  361.                     -c "deleteUI layerEditorWnd" closeButton;
  362.             setParent ..;
  363.  
  364.             formLayout -e
  365.                 -af layerList top 5
  366.                 -ac layerList right 5 layerEdBtnLayout
  367.                 -af layerList left 5
  368.                 -ac layerList bottom 5 layerSep
  369.  
  370.                 -af layerEdBtnLayout top 5
  371.                 -af layerEdBtnLayout right 5
  372.                 -an layerEdBtnLayout left
  373.                 -ac layerEdBtnLayout bottom 5 layerSep
  374.         
  375.                 -af layerSep left 0
  376.                 -af layerSep right 0
  377.                 -ac layerSep bottom 5 updateButton
  378.                 -an layerSep top
  379.  
  380.                 -af updateButton left 5
  381.                 -af updateButton bottom 5
  382.                 -ap updateButton right 3 50
  383.                 -an updateButton top 
  384.  
  385.                 -ap closeButton left 2 50
  386.                 -af closeButton bottom 5
  387.                 -af closeButton right 5
  388.                 -an closeButton top 
  389.                 layerEditorForm;
  390.             
  391.             formLayout characterForm;
  392.                 outlinerEditor -mainListConnection characterList 
  393.                     -selectionConnection highlightList characterOutliner;
  394.                 columnLayout characterBtnLayout;
  395.                     button -h 26 -w 80 -l "Set Key"         
  396.                         -c "performSetKeyframeCharacter false" 
  397.                         keyframeButton;
  398.                     button -h 26 -w 80 -l "Set Breakdown"         
  399.                         -c "performSetBreakdownCharacter false" 
  400.                         breakdownButton;
  401.                 
  402.                     separator -style "in" -w 80 -h 10;
  403.                     
  404.                     button -h 26 -w 80 -l "Clear"         
  405.                         -c "selectionConnection -edit -clear highlightList" 
  406.                         clearSelectionButton;
  407.  
  408.                 setParent ..;
  409.             formLayout -e
  410.                 -af characterOutliner top 5
  411.                 -ac characterOutliner right 5 characterBtnLayout
  412.                 -af characterOutliner left 5
  413.                 -af characterOutliner bottom 5
  414.  
  415.                 -af characterBtnLayout top 5
  416.                 -af characterBtnLayout right 5
  417.                 -an characterBtnLayout left
  418.                 -af characterBtnLayout bottom 5
  419.                 characterForm;
  420.  
  421.         tabLayout -edit -tabLabel layerEditorForm "Layers" 
  422.             -tabLabel characterForm "Characters" layerEditorTabLayout;
  423.  
  424.  
  425.     //    Create script jobs to keep the layer editor up to date
  426.     //    when new layers are added to the system, File -> New
  427.     //    is performed, or a file is imported/opened
  428.  
  429.     scriptJob 
  430.         -p "layerEditorWnd"
  431.         -e "layerPartitionModified"
  432.         "updateLayerEditorWnd";
  433.  
  434.     scriptJob 
  435.         -p "layerEditorWnd"
  436.         -e "NewSceneOpened"
  437.         "updateLayerEditorWnd";
  438.  
  439.     scriptJob 
  440.         -p "layerEditorWnd"
  441.         -e "SceneOpened"
  442.         "updateLayerEditorWnd";
  443.  
  444.     updateLayerEditorWnd;
  445.     showWindow layerEditorWnd;
  446. }
  447.